home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0039 / generatr / cut.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  8KB  |  320 lines

  1. #include <bitmap.h>
  2. #include <extdefs.h>
  3. #include <osbind.h>
  4. #include <stdio.h>
  5. #include <gemdefs.h>
  6.  
  7. extern int work_out[];
  8.  
  9.  
  10. /* See if the screen is blank */
  11. int search_blank(pointer)
  12. long *pointer;
  13. {
  14. int i;
  15.  
  16.     for( i=0; i<8000; i++ ) if( *pointer++ ) return( 1 );
  17.  
  18.         return( 0 );
  19.  
  20. }
  21.  
  22. /* Interact with the user to get the coordinates of the box */
  23. int cut_image(pointer,old_cutflag)
  24. long pointer;
  25. int old_cutflag;
  26. {
  27.     char junk[20];
  28.     int flag;
  29.     int cflag;
  30.     int horizontal[4];
  31.     int vertical[4];
  32.     int rectangle[10];
  33.     long oldscreen;
  34.     int oldx, oldy;
  35.     int new_cutflag;
  36.     int x, y;
  37.  
  38.     switch( rez ){
  39.         case 0:    x = 1; y = 1; break;
  40.         case 1:    x = 2; y = 1; break;
  41.         case 2:    x = 2; y = 2; break;
  42.         }
  43.  
  44.    /* wait for the mouse button to be released */
  45.    do{ GET_MOUSE; } while( button );
  46.  
  47.     /* Get the current screen location */
  48.     oldscreen = Physbase();
  49.  
  50.     HIDE_MOUSE;
  51.  
  52.     Setscreen( pointer, pointer, -1 ); /* Show the screen */
  53.  
  54.     vswr_mode( handle, 3 );
  55.     vsl_color( handle, 1 );
  56.  
  57.     horizontal[0] = 0;
  58.     horizontal[2] = work_out[0];
  59.     horizontal[1] = horizontal[3] = my;
  60.  
  61.     vertical[1] = 0;
  62.     vertical[3] = work_out[1];
  63.     vertical[0] = vertical[2] = mx;
  64.  
  65.     flag = 0;
  66.  
  67.     do{
  68.  
  69.     if( my > 8 * y ) cflag = 1;
  70.             else cflag = 3;
  71.  
  72.     text_box( pointer, temp_scrn, 0, cflag );
  73.  
  74.       do{
  75.     /* Draw the lines */
  76.     horizontal[1] = horizontal[3] = my;
  77.     vertical[0] = vertical[2] = mx;
  78.  
  79.     v_pline( handle, 2, horizontal );
  80.     v_pline( handle, 2, vertical );
  81.  
  82.     do{ GET_MOUSE;
  83.       } while((Bconstat(2)==0)&&(button==0)&&(mx==oldx)&&(my==oldy)); 
  84.  
  85.     v_pline( handle, 2, horizontal );
  86.     v_pline( handle, 2, vertical );
  87.  
  88.     sprintf( junk, "X:%03d Y:%03d", mx, my );
  89.  
  90.     if( cflag == 1 && my < 8 * y ){
  91.         cflag = 3;
  92.         text_box( pointer, temp_scrn, 1, 1 );
  93.         text_box( pointer, temp_scrn, 0, 3 );
  94.         }
  95.     else if( cflag == 3 && my > 191 * y ){
  96.         cflag = 1;
  97.         text_box( pointer, temp_scrn, 1, 3 );
  98.         text_box( pointer, temp_scrn, 0, 1 );
  99.         }
  100.  
  101.     vswr_mode( handle, 1 );
  102.  
  103.     switch( cflag ){
  104.         case 1:    v_gtext( handle, 0, 6*y, junk );
  105.                 break;
  106.         case 3:    v_gtext( handle, 0, 198*y, junk );
  107.                 break;
  108.         }
  109.  
  110.     vswr_mode( handle, 3 );
  111.  
  112.     oldx = mx;    oldy = my;
  113.  
  114.     } while( button == 0 && Bconstat(2) == 0 );
  115.  
  116.     text_box( pointer, temp_scrn, 1, cflag );
  117.  
  118.       if( Bconstat(2) != 0 )
  119.       {
  120.       Bconin(2);
  121.       new_cutflag = old_cutflag;
  122.       break;
  123.       }
  124.  
  125.       do{ GET_MOUSE; } while( button );
  126.  
  127.       /* define the constant coordinates for the rubber band box */
  128.       rectangle[0] = rectangle[6] = rectangle[8] = mx;
  129.       rectangle[1] = rectangle[3] = rectangle[9] = my;
  130.  
  131.         if( my > 8 * y ) cflag = 1;
  132.                 else cflag = 3;
  133.  
  134.         text_box( pointer, temp_scrn, 0, cflag );
  135.  
  136.       do{
  137.     /* define/change the variable rubber band box coordinates */
  138.     rectangle[2] = rectangle[4] = mx;
  139.     rectangle[5] = rectangle[7] = my;
  140.     v_pline( handle, 5, rectangle );
  141.  
  142.     sprintf( junk, "W:%03d H:%03d", abs( rectangle[0] - rectangle[2] ) + 1, abs( rectangle[1] - rectangle[5] ) + 1 );
  143.  
  144.     if( !cflag ){
  145.         if( rectangle[1] > 8*y && rectangle[5] > y*8 ) cflag = 1;
  146.         else if( rectangle[1] < y*191 && rectangle[5] < y*191 ) cflag = 3;
  147.         else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 2;
  148.         else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 1;
  149.         if( cflag ){
  150.             v_pline( handle, 5, rectangle );
  151.             text_box( pointer, temp_scrn, 0, cflag );
  152.             v_pline( handle, 5, rectangle );
  153.             }
  154.         }
  155.     else if( cflag == 1 && ( rectangle[1] < y*8 || rectangle[5] < y*8 ) && ( rectangle[0] < x*160 || rectangle[2] < x*160 ) ){
  156.         if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 2;
  157.         else if( rectangle[1] < y*191 && rectangle[5] < y*191 ) cflag = 3;
  158.         else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 3;
  159.         else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 4;
  160.         else cflag = 0;
  161.         v_pline( handle, 5, rectangle );
  162.         text_box( pointer, temp_scrn, 1, 1 );
  163.         if( cflag ) text_box( pointer, temp_scrn, 0, cflag );
  164.         v_pline( handle, 5, rectangle );
  165.         }
  166.     else if( cflag == 2 && ( rectangle[1] < y*8 || rectangle[5] < y*8 ) && ( rectangle[0] > x*160 || rectangle[2] > x*160 ) ){
  167.         if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 1;
  168.         else if( rectangle[1] < y*191 && rectangle[5] < y*191 ) cflag = 3;
  169.         else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 3;
  170.         else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 4;
  171.         else cflag = 0;
  172.         v_pline( handle, 5, rectangle );
  173.         text_box( pointer, temp_scrn, 1, 2 );
  174.         if( cflag ) text_box( pointer, temp_scrn, 0, cflag );
  175.         v_pline( handle, 5, rectangle );
  176.         }
  177.     else if( cflag == 3 && ( rectangle[1] > y*191 || rectangle[5] > y*191 ) && ( rectangle[0] < x*160 || rectangle[2] < x*160 ) ){
  178.         if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 4;
  179.         else if( rectangle[1] > y*8 && rectangle[5] > y*8 ) cflag = 1;
  180.         else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 1;
  181.         else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 2;
  182.         else cflag = 0;
  183.         v_pline( handle, 5, rectangle );
  184.         text_box( pointer, temp_scrn, 1, 3 );
  185.         if( cflag ) text_box( pointer, temp_scrn, 0, cflag );
  186.         v_pline( handle, 5, rectangle );
  187.         }
  188.     else if( cflag == 4 && ( rectangle[1] > y*191 || rectangle[5] > y*191 ) && ( rectangle[0] > x*160 || rectangle[2] > x*160 ) ){
  189.         if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 3;
  190.         else if( rectangle[1] > y*8 && rectangle[5] > y*8 ) cflag = 1;
  191.         else if( rectangle[0] > x*160 && rectangle[2] > x*160 ) cflag = 1;
  192.         else if( rectangle[0] < x*160 && rectangle[2] < x*160 ) cflag = 2;
  193.         else cflag = 0;
  194.         v_pline( handle, 5, rectangle );
  195.         text_box( pointer, temp_scrn, 1, 4 );
  196.         if( cflag ) text_box( pointer, temp_scrn, 0, cflag );
  197.         v_pline( handle, 5, rectangle );
  198.         }
  199.  
  200.     vswr_mode( handle, 1 );
  201.  
  202.     switch( cflag ){
  203.         case 0:    break;
  204.         case 1:    v_gtext( handle, 0, 6*y, junk );
  205.                 break;
  206.         case 2:    v_gtext( handle, 160*x, 6*y, junk );
  207.                 break;
  208.         case 3:    v_gtext( handle, 0, 198*y, junk );
  209.                 break;
  210.         case 4:    v_gtext( handle, 160*x, 198*y, junk );
  211.                 break;
  212.         }
  213.  
  214.     vswr_mode( handle, 3 );
  215.  
  216.     do{ GET_MOUSE;
  217.       } while((Bconstat(2)==0)&&(button==0)&&(mx==oldx)&&(my==oldy));
  218.  
  219.     v_pline( handle, 5, rectangle );
  220.  
  221.     oldx = mx;    oldy = my;
  222.  
  223.     } while( button == 0 && Bconstat(2) == 0 );
  224.  
  225.     if( cflag ) text_box( pointer, temp_scrn, 1, cflag );
  226.  
  227.     if( button )
  228.         {
  229.         new_cutflag = 1;
  230.         }
  231.     else
  232.         {
  233.         Bconin(2);
  234.         new_cutflag = 0;
  235.         }
  236.  
  237.       } while( new_cutflag == 0 );
  238.  
  239.     /* Make sure that the new screen is set */
  240.     Vsync();
  241.  
  242.     SHOW_MOUSE;
  243.  
  244.     do{ GET_MOUSE; graf_mkstate( &flag, &flag, &oldy, &flag ); }while( button || oldy );
  245.  
  246.    oldx = evnt_multi( MU_MESAG|MU_TIMER, -1, -1, -1,
  247.                         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  248.                         rectangle, 500, 0,
  249.                         &flag, &flag, &flag, &flag, &flag, &flag );
  250.  
  251.     /* Restore the old screen pointer */
  252.     Setscreen( oldscreen, oldscreen, -1 );
  253.  
  254.     if( new_cutflag == 0 ) return(0);
  255.  
  256.     rx1 = rectangle[0];
  257.     ry1 = rectangle[1];
  258.     rx2 = rectangle[4];
  259.     ry2 = rectangle[5];
  260.  
  261.     return(1);
  262.  
  263. }/* End cut_image() function */
  264.  
  265.  
  266. sscreen( mode )
  267. int mode;
  268. {
  269. unsigned int i;
  270. long *p1, *p2;
  271.  
  272.     p1 = (long *)Physbase();
  273.     p2 = (long *)undo_scrn;
  274.  
  275.     for( i=0; i<8000; i++ ){
  276.         if( mode == RESTORE ) *p1++ = *p2++;
  277.                 else      *p2++ = *p1++;
  278.         }
  279.  
  280. }
  281.  
  282. text_box( visual, remote, flag, cflag )
  283. long *visual, *remote;
  284. int flag, cflag;
  285. {
  286. int i, j, k, l;
  287.  
  288.  
  289.         if( rez == 2 )
  290.             k = 1, l = 2;
  291.         else
  292.             k = 2, l = 1;
  293.  
  294.     switch( cflag ){
  295.         case 2:    visual += 20L;
  296.             if( rez == 2 ) visual -= 10L;
  297.                 break;
  298.         case 3:    visual += 7680L;
  299.                 break;
  300.         case 4:    visual += 7700L;
  301.             if( rez == 2 ) visual -= 10L;
  302.                 break;
  303.         }
  304.  
  305.     for( i=0; i<8*l; i++ ){
  306.         for( j=0; j<k*10; j++ ){
  307.  
  308.             if( !flag ) *remote++ = *visual++;
  309.                 else    *visual++ = *remote++;
  310.  
  311.             }
  312.  
  313.         if( rez != 2 )
  314.                    visual += 20L;
  315.         else
  316.             visual += 10L;
  317.         }
  318.  
  319. }
  320.